package com.dmcb.trade.business.crawlers.article;

import com.dmcb.trade.business.constants.CrawlConstant;
import com.dmcb.trade.business.entities.Article;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Service;

/**
 * 网易文章解析
 * Created by Administrator on 2016/4/28.
 */
@Service
public class WangyiParser extends BaseParser {

    /**
     * 网站URL网址
     *
     * @return 链接
     */
    @Override
    protected String url() {
        return CrawlConstant.WANGYI_URL;
    }

    /**
     * 获取标题选择器
     *
     * @return 标题选择器
     */
    @Override
    protected String titleSelect() {
        return "h2.wap_h22>a,h1.g-title,div.cont_left>h1,h1.art-title,div.ds_page_content>h2.ds_page_til,div.deal-content,div#epContentLeft>h1,h2,h1.title";
    }

    /**
     * 获取日期选择器
     *
     * @return 发布日期选择器
     */
    @Override
    protected String dateSelect() {
        return "div.post_time_source,p.time,span.js-time";
    }

    /**
     * 获取正文内容选择器
     *
     * @return 正文内容选择器
     */
    @Override
    protected String bodySelect() {
        return "div.art-content,div#endText,div#content,div.content";
    }

    /**
     * 获取封面选择器
     *
     * @return 封面选择器
     */
    @Override
    protected String coverSelect() {
        return "div#endText>p.f_center img[src],div#content img[src],div.content img[src]";
    }

    /**
     * 获取作者选择器
     *
     * @return 作者选择器
     */
    @Override
    protected String authorNameSelect() {
        return "div.ep-source >span.ep-editor,span.js-source";
    }

    @Override
    protected void setAuthorName(Document doc, Article article) {
        Elements elements = doc.select("p.time>span");
        if(elements.size()>2){
            article.setAuthorName(elements.last().text());
        }else{
            elements = doc.select(authorNameSelect());
            article.setAuthorName(elements.last().text());
        }
    }

    @Override
    protected String platform() {
        return "网易";
    }

}
